/* *  
 * Copyright (C) 2004-2008 Mocha Almond Fudge AI, SIT KMUTT
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package jboard.ui;

import java.awt.Dimension;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;

import jboard.model.IBoardConstant;
import jboard.util.SwingUtil;

/**
 * Factory class which handle theme changing in the game
 * 
 * @author Vashira Ravipanich
 */
public class ThemeFactory implements IBoardConstant {
    public static Dimension boardSize 
    = new Dimension(CELL_SIZE * 8 + 2, CELL_SIZE * 8 + 2);
    
    public static JLayeredPane renderBG(JLayeredPane layeredPane, String themeName) {
        ImageIcon bgIcon1 = null;
        ImageIcon bgIcon2 = null;
        
        if(themeName.equals(STANDARD)) {
            bgIcon1 = SwingUtil.getIcon(ThemeFactory.class.getClassLoader(), "img/StandardBG1.gif");
            bgIcon2 = SwingUtil.getIcon(ThemeFactory.class.getClassLoader(), "img/StandardBG2.gif");
            for(int x = 0; x < 8; x++) {
    			for(int y = 0; y < 8; y++) {
    			    if((x % 2 == 0 && y % 2 == 0) || (x % 2 == 1 && y % 2 == 1)) {
    			        JLabel bgLabel = new JLabel(bgIcon1);
        			    bgLabel.setBounds(0, 0, CELL_SIZE, CELL_SIZE);
        			    bgLabel.setLocation(x * CELL_SIZE, y * CELL_SIZE);
        			    layeredPane.add(bgLabel, new Integer(BOARD_LAYER));
    			    } else {
    			        JLabel bgLabel = new JLabel(bgIcon2);
        			    bgLabel.setBounds(0, 0, CELL_SIZE, CELL_SIZE);
        			    bgLabel.setLocation(x * CELL_SIZE, y * CELL_SIZE);
        			    layeredPane.add(bgLabel, new Integer(BOARD_LAYER));
    			    }
    			}
            }
        }
        
        if(themeName.equals(FREEZE)) {
            bgIcon1 = SwingUtil.getIcon(ThemeFactory.class.getClassLoader(), "img/FreezeBG1.gif");
            bgIcon2 = SwingUtil.getIcon(ThemeFactory.class.getClassLoader(), "img/FreezeBG2.gif");
            for(int x = 0; x < 8; x++) {
    			for(int y = 0; y < 8; y++) {	 
    			    if((x % 2 == 0 && y % 2 == 0) || (x % 2 == 1 && y % 2 == 1)) {
    			        JLabel bgLabel = new JLabel(bgIcon1);
        			    bgLabel.setBounds(0, 0, CELL_SIZE, CELL_SIZE);
        			    bgLabel.setLocation(x * CELL_SIZE, y * CELL_SIZE);
        			    layeredPane.add(bgLabel, new Integer(BOARD_LAYER));
    			    } else {
    			        JLabel bgLabel = new JLabel(bgIcon2);
        			    bgLabel.setBounds(0, 0, CELL_SIZE, CELL_SIZE);
        			    bgLabel.setLocation(x * CELL_SIZE, y * CELL_SIZE);
        			    layeredPane.add(bgLabel, new Integer(BOARD_LAYER));
    			    }
    			}
            }
        }
        
        
        return layeredPane;
    }

    public static JLabel createFloater() {
        ImageIcon bgIcon = SwingUtil.getIcon(ThemeFactory.class.getClassLoader(), "img/Floater1.gif");
        return new JLabel(bgIcon);
    }
    
    public static JLabel createToken(String themeName, int color) {
        ImageIcon bgIcon = null;
        switch(color) {
        case BLACK:
            if(themeName.equals(STANDARD)) {
                bgIcon = SwingUtil.getIcon(ThemeFactory.class.getClassLoader(), "img/Black-Token.gif");
            }
            if(themeName.equals(FREEZE)) {
                bgIcon = SwingUtil.getIcon(ThemeFactory.class.getClassLoader(), "img/Black-Token-Freeze.gif");
            }
            break;
        case WHITE:
            if(themeName.equals(STANDARD)) {
                bgIcon = SwingUtil.getIcon(ThemeFactory.class.getClassLoader(), "img/White-Token.gif");
            }
            if(themeName.equals(FREEZE)) {
                bgIcon = SwingUtil.getIcon(ThemeFactory.class.getClassLoader(), "img/White-Token-Freeze.gif");
            }
            break;
        }
        return new JLabel(bgIcon);
    }
    
    public static JLabel createAvatar(int message) {
        ImageIcon bgIcon = null;
        
        switch(message) {
        case HI_AVATAR:
            bgIcon = SwingUtil.getIcon(ThemeFactory.class.getClassLoader(), "img/avatar/hi-avatar.gif");
            break;
        case WIN_AVATAR:
            bgIcon = SwingUtil.getIcon(ThemeFactory.class.getClassLoader(), "img/avatar/ai-win-avatar.gif");
            break;
        case DON_SEAB_AVATAR:
            bgIcon = SwingUtil.getIcon(ThemeFactory.class.getClassLoader(), "img/avatar/donseab-avatar.gif");
            break;
        case DON_NEAB_AVATAR:
            bgIcon = SwingUtil.getIcon(ThemeFactory.class.getClassLoader(), "img/avatar/donneab-avatar.gif");
            break;
        case HAHAHA_AVATAR:
            bgIcon = SwingUtil.getIcon(ThemeFactory.class.getClassLoader(), "img/avatar/555-avatar.gif");
            break;
        case LOE_AVATAR:
            bgIcon = SwingUtil.getIcon(ThemeFactory.class.getClassLoader(), "img/avatar/loe-avatar.gif");
            break;
        }
        
        return new JLabel(bgIcon);
    }
    
}
